package com.analysis.util;

import java.io.IOException;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

public class JarVersionExtractor {
    
    public static String extractVersion(JarFile jarFile) throws IOException {
        Manifest manifest = jarFile.getManifest();
        if (manifest != null) {
            String version = manifest.getMainAttributes().getValue("Implementation-Version");
            if (version != null) {
                return version;
            }
            version = manifest.getMainAttributes().getValue("Bundle-Version");
            if (version != null) {
                return version;
            }
        }
        return "Unknown";
    }
    
    public static boolean isSpringCloudJar(JarFile jarFile) throws IOException {
        Manifest manifest = jarFile.getManifest();
        if (manifest != null) {
            String name = manifest.getMainAttributes().getValue("Implementation-Title");
            return name != null && (name.contains("spring-cloud") || name.contains("spring-boot"));
        }
        return false;
    }
}
